import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { getToken } from '@/utils/auth'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      name: 'home',
      component: HomeView
    },
    {
      path: '/',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/LoginView.vue')
    }
  ]
})
// router.beforeEach((to, from) => {
//   const isAuthenticated = getToken()
//   if (
//     // 检查用户是否已登录
//     !isAuthenticated &&
//     // ❗️ 避免无限重定向
//     to.name !== 'login'
//   ) {
//     // 将用户重定向到登录页面
//     return { name: 'login' }
//   }
// })
export default router
